<?php 
/* this file will handle product shippment; can be marked as pending, shipped or returned */
// load wordpress defaults, make global variables/functions available 
$this_file = str_replace( '\\', '/', __FILE__ );
$this_file = explode( 'wp-content', $this_file );
$this_file = $this_file[ 0 ];
require( $this_file . 'wp-blog-header.php' );
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<!-- head start -->

<head profile="http://gmpg.org/xfn/11">
	<?php
    $aOptions = SofaSuppaStore::initOptions( false );
	// handle font selection
	$google_fonts = $aOptions[ 'google_fonts' ];
	$font_str = $google_fonts;
	$font_str_arr = explode( ':', $font_str );
	$font_name = $font_str_arr[ 0 ];
	$clean_font_arr = explode( '+', $font_name );
	$clean_font_name = implode( ' ', $clean_font_arr );
    ?>
    <link href='http://fonts.googleapis.com/css?family=<?php echo $google_fonts; ?>' rel='stylesheet' type='text/css' />
    <link rel="stylesheet" href="<?php echo( get_template_directory_uri() . '/960.css' ); ?>" type="text/css" media="screen, projection" />
    <link rel="stylesheet" href="<?php echo( get_template_directory_uri() . '/screen.css' ); ?>" type="text/css" media="screen, projection" />
    <style type="text/css">
	/* handle basic styles according to google fonts selection */
	h1, h2, h3, h4, h5, h6 { font-family: '<?php echo $clean_font_name; ?>', Arial, sans-serif; font-weight: normal; }
	</style>
	<link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>" type="text/css" media="screen, projection" />
    
    <?php wp_print_scripts( 'jquery' ); ?>
    <script src="<?php echo( get_template_directory_uri() . '/script/jquery.suppastore.custom.js' ); ?>" type="text/javascript"></script>
</head>

<!-- head end -->

<body>

<!-- main content start -->

<div id="lightcontent" class="container_8 clearfix">
    
	<?php
	global $current_user;
	get_currentuserinfo();
	if( current_user_can( 'administrator' ) ) {
		
		// get item details
		if( $_SERVER[ 'REQUEST_METHOD' ] == 'GET' ) {
			$itemid  = !empty( $_GET[ 'itemid' ] ) ? intval( urldecode( $_GET[ 'itemid' ] ) ) : NULL; // product id
		} elseif( $_SERVER[ 'REQUEST_METHOD' ] == 'REQUEST' ) {
			$itemid = !empty( $_REQUEST[ 'itemid' ] ) ? intval( urldecode( $_REQUEST[ 'itemid' ] ) ) : NULL; // product id
		}
		
		if( $itemid ) {
			
			global $wpdb;
			$t_uc = '';
			$t_fs = '';
			$order_details = $wpdb->get_results( "SELECT flag_shipped, unique_code FROM " . $wpdb->prefix . "purchases_history WHERE id = $itemid" );
	
			if( $order_details ) {
				$t_uc = $order_details[ 0 ]->unique_code;
				$t_fs = $order_details[ 0 ]->flag_shipped;
			}
	?>

    <div id="featured" class="grid_8">
    
    	<!-- title start -->
    
        <h2 class="grid_8 alpha omega"><?php _e( "Modify order status", "sofa_suppastore" ); ?></h2>
        
        <!-- title start -->
        
        <div class="grid_8 alpha omega">
        
        	<p><?php echo __( "You are about to modify order status. This modification relates to order number:", "sofa_suppastore" ) . ' ' . $t_uc; ?></p>
            
            <!-- shipping state form start -->
        
            <form method="post" action="<?php echo ( get_template_directory_uri() . '/order_n553x000_ss.php' ); ?>">
            
                <input type="radio" name="order_state" value="0" tabindex="790" <?php if( $t_fs == 0 ) echo 'checked="checked"'; ?> />
                <label for="order_state" class="radiolabel"><?php _e( "Pending", "sofa_suppastore" ); ?></label>

                <input type="radio" name="order_state" value="1" tabindex="791" <?php if( $t_fs == 1 ) echo 'checked="checked"'; ?> />
                <label for="order_state" class="radiolabel"><?php _e( "Shipped", "sofa_suppastore" ); ?></label>

                <input type="radio" name="order_state" value="2" tabindex="792" <?php if( $t_fs == 2 ) echo 'checked="checked"'; ?> />
                <label for="order_state" class="radiolabel"><?php _e( "Returned", "sofa_suppastore" ); ?></label>

            	<input type="hidden" name="itemid" id="itemid" value="<?php echo $itemid; ?>" />
                <input type="hidden" name="action" id="action" value="flag" />
                
                <?php wp_nonce_field( 'chck_ref_cc', 'sofa_suppastore_cc' ); ?>
                <button type="submit" id="submit" class="right" value="" tabindex="793"><?php _e( "Update", "sofa_suppastore" ); ?></button>
            
            </form>
            
            <!-- shipping state form end -->
        
        </div>
        
    </div>
    
    <?php 
		}
		
	} else { 
	?>
    
    <!-- permission denied start -->
    
    <div id="featured" class="grid_8">
    
        <h2 class="grid_8 alpha omega"><font style="color: #ED1C24;"><?php _e( "Error!", "sofa_suppastore" ); ?></font></h2>
        
        <div class="grid_8 alpha omega">
        
        	<?php _e( "You don't have a permission to perform this action!", "sofa_suppastore" ); ?>
        
        </div>
        
    </div>
    
    <!-- permission denied end -->
    
    <?php } ?>
        
</div>

<!-- main content end -->

</body>
</html>